package lj.courseinterect.rest.resources;

import lj.courseinterect.dao.i.ExamInfoDao;
import lj.courseinterect.dao.i.ExamItemDao;
import lj.courseinterect.entity.ExamInfo;
import lj.courseinterect.entity.ExamItem;
import lj.courseinterect.transfer.OperationTransfer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.Date;


@Component
@Path("/exam_item")
public class ExamItemResource
{
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ExamItemDao examItemDao;


    public Logger getLogger() {
        return logger;
    }

    public ExamItemDao getExamItemDao() {
        return examItemDao;
    }

    public void setExamItemDao(ExamItemDao examItemDao) {
        this.examItemDao = examItemDao;
    }

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public OperationTransfer create(ExamItem examItem)
    {
        this.logger.info("create(): " + examItem.getEiAns());
        OperationTransfer operationTransfer;

        try {
            this.examItemDao.save(examItem);
            operationTransfer = new OperationTransfer(true, "添加习题成功");
        } catch (Exception ex){
            operationTransfer = new OperationTransfer(false, "添加习题失败");
        }

        this.logger.info("create(): " + operationTransfer.toString());
        return operationTransfer;
    }


}